package mypackage;

import java.util.Random;
import java.util.Scanner;

public class testclass8 {
    public static void main(String[] args) {
        /*双色球,前6个为红球,最后1个为蓝球

        红球之间不能相等
        蓝球可以和红球相等

        中奖情况不分红球的顺序,只判断红球中奖几个,蓝球中奖几个
        */
        //创建大奖数组
        int[] grade=createarr();
        //输出大奖数组
        printarr(grade);

        //输入用户数组
        int[] myarr=getarr();
        //输出用户数组
        printarr(myarr);

        //获取6个红球的中奖情况
        int rednum=getrednum(grade,myarr);
        //获取第7个蓝球的中奖情况
        int bluenum=getbluenum(grade,myarr);

        //判断中奖情况
        qingkuang(rednum,bluenum);

    }
    public static int[] createarr(){
        int[]arr =new int[7];//6红1蓝
        Random r=new Random();
        for (int i = 0; i < arr.length-1; ) {
            int num=r.nextInt(33)+1;
            boolean flag=check(arr,num);
            if(!flag){
                arr[i]=num;
                ++i;
            }
        }
        arr[arr.length-1]=r.nextInt(16)+1;
        return arr;
    }
    public static boolean check(int[] arr,int num){
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]==num){
                return true;
            }
        }
        return false;
    }
    public static int[] getarr(){
        int[] myarr=new int[7];
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < myarr.length-1; ) {
            System.out.println("请输入第"+(i+1)+"个彩票号码");
            int num=sc.nextInt();
            boolean flag=check(myarr,num);
            if(!flag && num>=1&&num<=33){
                myarr[i]=num;
                ++i;
            }
            else{
                System.out.println("输入的数据不合法");
            }
        }
        System.out.println("请输入第"+(myarr.length)+"个彩票号码");
        myarr[myarr.length-1]=sc.nextInt();
        return myarr;
    }
    public static void qingkuang(int rednum,int bluenum){
        if(rednum==6&&bluenum==1){
            System.out.println("恭喜你中了1000w");
        }else if(rednum==6&&bluenum==0){
            System.out.println("恭喜你中了500w");
        }else if(rednum==5&&bluenum==1){
            System.out.println("恭喜你中了3000");
        }else if((rednum==5&&bluenum==0) || (rednum==4&&bluenum==1)){
            System.out.println("恭喜你中了200");
        }else if((rednum==4&&bluenum==0) || (rednum==3&&bluenum==1)){
            System.out.println("恭喜你中了10");
        }else if((rednum==2&&bluenum==1) || (rednum==1&&bluenum==1) || (rednum==0&&bluenum==1)){
            System.out.println("恭喜你中了5");
        }else{
            System.out.println("谢谢参与");
        }
    }
    public static int getrednum(int[] grade,int[] myarr){
        int rednum=0;
        for (int i = 0; i < myarr.length-1; i++) {
            for (int i1 = 0; i1 < grade.length-1; i1++) {
                if(myarr[i]==grade[i1]){
                    ++rednum;
                    break;
                }
            }
        }
        return rednum;
    }
    public static int getbluenum(int[] grade,int[] myarr){
        int bluenum=0;
        if(grade[grade.length-1]==myarr[myarr.length-1]){
            ++bluenum;
        }
        return bluenum;
    }
    public static void printarr(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
}
